import java.util.Comparator;

public class StrategyPattern {
    public static void main(String[] args) {
        Cat[] cats = new Cat[]{new Cat(1, 1), new Cat(1, 3), new Cat(2, 1)};
        Sorter<Cat> sorter = new Sorter<Cat>();
        Cat[] catsSorted1 = sorter.sort(cats, new CatWeightComparator());
        Cat[] catsSorted2 = sorter.sort(cats, new CatHeightComparator());
    }
}

class Sorter<T> {
    T[] sort(T[] array, Comparator<T> comparator) {
        //排序算法省略
        return array;
    }
}

class Cat {
    private int height;
    private int weight;

    Cat(int height, int weight) {
        this.height = height;
        this.weight = weight;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }
}

class CatWeightComparator implements Comparator<Cat> {

    public int compare(Cat o1, Cat o2) {
        return o1.getWeight() - o2.getWeight();
    }
}

class CatHeightComparator implements Comparator<Cat> {

    public int compare(Cat o1, Cat o2) {
        return o1.getHeight() - o2.getHeight();
    }
}





